/*
 * $Id: tunnel.h,v 1.38.2.2 Broadcom SDK $
 * 
 * $Copyright: Copyright 2011 Broadcom Corporation.
 * This program is the proprietary software of Broadcom Corporation
 * and/or its licensors, and may only be used, duplicated, modified
 * or distributed pursuant to the terms and conditions of a separate,
 * written license agreement executed between you and Broadcom
 * (an "Authorized License").  Except as set forth in an Authorized
 * License, Broadcom grants no license (express or implied), right
 * to use, or waiver of any kind with respect to the Software, and
 * Broadcom expressly reserves all rights in and to the Software
 * and all intellectual property rights therein.  IF YOU HAVE
 * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
 * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
 * ALL USE OF THE SOFTWARE.  
 *  
 * Except as expressly set forth in the Authorized License,
 *  
 * 1.     This program, including its structure, sequence and organization,
 * constitutes the valuable trade secrets of Broadcom, and you shall use
 * all reasonable efforts to protect the confidentiality thereof,
 * and to use this information only in connection with your use of
 * Broadcom integrated circuit products.
 *  
 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
 * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
 * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
 * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
 * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
 * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
 * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
 * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
 * 
 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
 * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
 * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
 * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
 * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR USD 1.00,
 * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
 * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
 * 
 * DO NOT EDIT THIS FILE!
 * This file is auto-generated.
 * Edits to this file will be lost when it is regenerated.
 */

#ifndef __BCM_TUNNEL_H__
#define __BCM_TUNNEL_H__

#if defined(INCLUDE_L3)

#include <bcm/types.h>
#include <bcm/l3.h>

/* Tunnel flags. */
#define BCM_TUNNEL_TERM_DSCP_TRUST          0x00000001 /* Trust incoming tunnel
                                                          DSCP inner or outer
                                                          based on
                                                          USE_OUTER_DSCP flag. */
#define BCM_TUNNEL_TERM_USE_OUTER_DSCP      0x00000002 /* Use outer header DSCP. */
#define BCM_TUNNEL_TERM_USE_OUTER_TTL       0x00000004 /* Use outer header TTL. */
#define BCM_TUNNEL_TERM_KEEP_INNER_DSCP     0x00000008 /* Keep inner header
                                                          DSCP. */
#define BCM_TUNNEL_TERM_WLAN_REMOTE_TERMINATE 0x00000010 /* Remote WLAN tunnel
                                                          termination */
#define BCM_TUNNEL_TERM_WLAN_SET_ROAM       0x00000020 /* Set wlan ha/fa roaming
                                                          model */
#define BCM_TUNNEL_TERM_TUNNEL_WITH_ID      0x00000040 /* Create tunnel with ID */
#define BCM_TUNNEL_INIT_USE_INNER_DF        0x00000080 /* Copy DF from inner
                                                          header. Note:flag
                                                          takes precedence over
                                                          ipv4_set_df flag. */
#define BCM_TUNNEL_INIT_IPV4_SET_DF         0x00000100 /* Set DF bit in outer
                                                          header if inner header
                                                          is IPv4. */
#define BCM_TUNNEL_INIT_IPV6_SET_DF         0x00000200 /* Set DF bit in outer
                                                          header if inner header
                                                          is IPv6. */
#define BCM_TUNNEL_INIT_IP4_ID_SET_FIXED    0x00000400 /* Use fixed starting ID
                                                          for IPv4 tunnel */
#define BCM_TUNNEL_INIT_IP4_ID_SET_RANDOM   0x00000800 /* Use random starting ID
                                                          for IPv4 tunnel */
#define BCM_TUNNEL_INIT_WLAN_MTU            0x00001000 /* Set MTU for outgoing
                                                          WLAN tunnel */
#define BCM_TUNNEL_INIT_WLAN_VLAN_TAGGED    0x00002000 /* Set outgoing WLAN
                                                          tunnel vlan */
#define BCM_TUNNEL_INIT_WLAN_TUNNEL_WITH_ID 0x00004000 /* Create outgoing tunnel
                                                          with ID */
#define BCM_TUNNEL_REPLACE                  0x00008000 /* Update existing
                                                          tunnel. */

#define BCM_TUNNEL_INIT_SET_DF  \
    (BCM_TUNNEL_INIT_IPV6_SET_DF | \
     BCM_TUNNEL_INIT_IPV4_SET_DF) 

/* Tunnel types. */
typedef enum bcm_tunnel_type_e {
    bcmTunnelTypeNone,              /* Disable IP tunneling on specific
                                       interface. */
    bcmTunnelTypeIp4In4,            /* RFC 2003/2893: IPv4-in-IPv4 tunnel. */
    bcmTunnelTypeIp6In4,            /* RFC 2003/2893: IPv6-in-IPv4 tunnel. */
    bcmTunnelTypeIpAnyIn4,          /* RFC 2003/2893: IPv6/4-in-IPv4 tunnel. */
    bcmTunnelTypeIp4In6,            /* RFC 2003/2893: IPv4-in-IPv6 tunnel. */
    bcmTunnelTypeIp6In6,            /* RFC 2003/2893: IPv6-in-IPv6 tunnel. */
    bcmTunnelTypeIpAnyIn6,          /* RFC 2003/2893: IPv6/4-in-IPv6 tunnel. */
    bcmTunnelTypeGre4In4,           /* RFC 1701/2784/2890: GRE IPv4-in-IPv4
                                       tunnel. */
    bcmTunnelTypeGre6In4,           /* RFC 1701/2784/2890: GRE IPv6-in-IPv4
                                       tunnel. */
    bcmTunnelTypeGreAnyIn4,         /* RFC 1701/2784/2890: GRE IPv6/4-in-IPv4
                                       tunnel. */
    bcmTunnelTypeGre4In6,           /* RFC 1701/2784/2890: GRE IPv4-in-IPv6
                                       tunnel. */
    bcmTunnelTypeGre6In6,           /* RFC 1701/2784/2890: GRE IPv6-in-IPv6
                                       tunnel. */
    bcmTunnelTypeGreAnyIn6,         /* RFC 1701/2784/2890: GRE IPv6/4-in-IPv6
                                       tunnel. */
    bcmTunnelTypeIsatap,            /* RFC 4214: Intra-Site Automatic Tunnel
                                       Addressing Protocol. */
    bcmTunnelType6In4Uncheck,       /* RFC 3056: Configured connection of IPv6
                                       Domains via IPv4. */
    bcmTunnelType6In4,              /* RFC 3964: Checked 6to4 tunnel if
                                       supported by device otherwise unchecked
                                       6to4 tunnel. */
    bcmTunnelTypeMpls,              /* RFC 3031: MPLS tunneling. */
    bcmTunnelTypeUdp,               /* UDP tunneling */
    bcmTunnelTypePimSmDr1,          /* Broadcom PIM SM Tunnel */
    bcmTunnelTypePimSmDr2,          /* Broadcom PIM SM Tunnel */
    bcmTunnelTypePim6SmDr1,         /* Broadcom PIM6 SM Tunnel */
    bcmTunnelTypePim6SmDr2,         /* Broadcom PIM6 SM Tunnel */
    bcmTunnelTypeWlanWtpToAc,       /* IPv4 WLAN WTP to AC tunnel */
    bcmTunnelTypeWlanAcToAc,        /* IPv4 WLAN AC to AC tunnel */
    bcmTunnelTypeWlanWtpToAc6,      /* IPv6 WLAN WTP to AC tunnel */
    bcmTunnelTypeWlanAcToAc6,       /* IPv6 WLAN AC to AC tunnel */
    bcmTunnelTypeAutoMulticast,     /* IPV4 draft-ietf-mboned-auto-multicast-09:
                                       AMT */
    bcmTunnelTypeAutoMulticast6,    /* IPV6 draft-ietf-mboned-auto-multicast-09:
                                       AMT */
    bcmTunnelTypeCount              /* Must be last */
} bcm_tunnel_type_t;

#define BCM_TUNNEL_TYPE_STR \
    "None", \
    "Ip4In4", \
    "Ip6In4", \
    "IpAnyIn4", \
    "Ip4In6", \
    "Ip6In6", \
    "IpAnyIn6", \
    "Gre4In4", \
    "Gre6In4", \
    "GreAnyIn4", \
    "Gre4In6", \
    "Gre6In6", \
    "GreAnyIn6", \
    "Isatap", \
    "6In4Uncheck", \
    "6In4", \
    "Mpls", \
    "Udp", \
    "PimSmDr1", \
    "PimSmDr2", \
    "Pim6SmDr1", \
    "Pim6SmDr2", \
    "WlanWtpToAc", \
    "WlanAcToAc", \
    "WlanWtpToAc6", \
    "WlanAcToAc6", \
    "AutoMulticast", \
    "AutoMulticast6" 

/* L3 tunneling terminator. */
typedef struct bcm_tunnel_terminator_s {
    uint32 flags;               /* Configuration flags. */
    bcm_vrf_t vrf;              /* Virtual router instance. */
    bcm_ip_t sip;               /* SIP for tunnel header match. */
    bcm_ip_t dip;               /* DIP for tunnel header match. */
    bcm_ip_t sip_mask;          /* Source IP mask. */
    bcm_ip_t dip_mask;          /* Destination IP mask. */
    bcm_ip6_t sip6;             /* SIP for tunnel header match (IPv6). */
    bcm_ip6_t dip6;             /* DIP for tunnel header match (IPv6). */
    bcm_ip6_t sip6_mask;        /* Source IP mask (IPv6). */
    bcm_ip6_t dip6_mask;        /* Destination IP mask (IPv6). */
    uint32 udp_dst_port;        /* UDP dst port for UDP packets. */
    uint32 udp_src_port;        /* UDP src port for UDP packets */
    bcm_tunnel_type_t type;     /* Tunnel type */
    bcm_pbmp_t pbmp;            /* Port bitmap for this tunnel */
    bcm_vlan_t vlan;            /* The VLAN ID for IPMC lookup or WLAN tunnel */
    bcm_gport_t remote_port;    /* Remote termination */
    bcm_gport_t tunnel_id;      /* Tunnel id */
    int if_class;               /* L3 interface class this tunnel. */
} bcm_tunnel_terminator_t;

/* bcm_tunnel_dscp_select_e */
typedef enum bcm_tunnel_dscp_select_e {
    bcmTunnelDscpAssign,    /* Set outer IP header DSCP to tunnel initiator DSCP
                               value. */
    bcmTunnelDscpPacket,    /* Copy packet DSCP to outer header. */
    bcmTunnelDscpMap,       /* Use DSCP value from DSCP map. */
    bcmTunnelDscpCount      /* Unused always last. */
} bcm_tunnel_dscp_select_t;

/* L3 tunneling initiator. */
typedef struct bcm_tunnel_initiator_s {
    uint32 flags;                       /* Configuration flags. */
    bcm_tunnel_type_t type;             /* Tunnel type. */
    int ttl;                            /* Tunnel header TTL. */
    bcm_mac_t dmac;                     /* Destination MAC address. */
    bcm_ip_t dip;                       /* Tunnel header DIP (IPv4). */
    bcm_ip_t sip;                       /* Tunnel header SIP (IPv4). */
    bcm_ip6_t sip6;                     /* Tunnel header SIP (IPv6). */
    bcm_ip6_t dip6;                     /* Tunnel header DIP (IPv6). */
    uint32 flow_label;                  /* Tunnel header flow label (IPv6). */
    bcm_tunnel_dscp_select_t dscp_sel;  /* Tunnel header DSCP select. */
    int dscp;                           /* Tunnel header DSCP value. */
    int dscp_map;                       /* DSCP-map ID. */
    bcm_gport_t tunnel_id;              /* Tunnel ID */
    uint16 udp_dst_port;                /* Destination UDP port */
    uint16 udp_src_port;                /* Source UDP port */
    bcm_mac_t smac;                     /* WLAN outer MAC */
    int mtu;                            /* WLAN MTU */
    bcm_vlan_t vlan;                    /* Tunnel VLAN */
    uint16 tpid;                        /* Tunnel TPID */
    uint8 pkt_pri;                      /* Tunnel priority */
    uint8 pkt_cfi;                      /* Tunnel CFI */
    uint16 ip4_id;                      /* IPv4 ID. */
} bcm_tunnel_initiator_t;

/* L3 Tunnel Configuration Structure. */
typedef struct bcm_tunnel_config_s {
    int ip4_id;             /* Global ID. */
    uint32 ms_pimsm_hdr1;   /* Most significant 32 bits of PIMSM-DR1 header */
    uint32 ls_pimsm_hdr1;   /* Least significant 32 bits of PIMSM-DR1 header. */
    uint32 ms_pimsm_hdr2;   /* Most significant 32 bits of PIMSM-DR2 header. */
    uint32 ls_pimsm_hdr2;   /* Least significant 32 bits of PIMSM-DR2 header. */
} bcm_tunnel_config_t;

/* Tunnel DSCP Map Structure. */
typedef struct bcm_tunnel_dscp_map_s {
    int priority;       /* Internal priority. */
    bcm_color_t color;  /* Color. */
    int dscp;           /* DSCP value. */
} bcm_tunnel_dscp_map_t;

#ifndef BCM_HIDE_DISPATCHABLE

/* Set the tunneling initiator parameters on an L3 interface. */
extern int bcm_tunnel_initiator_set(
    int unit, 
    bcm_l3_intf_t *intf, 
    bcm_tunnel_initiator_t *tunnel);

/* Delete the tunnel association for the given L3 interface. */
extern int bcm_tunnel_initiator_clear(
    int unit, 
    bcm_l3_intf_t *intf);

/* Get the tunnel property for the given L3 interface. */
extern int bcm_tunnel_initiator_get(
    int unit, 
    bcm_l3_intf_t *intf, 
    bcm_tunnel_initiator_t *tunnel);

/* Add a tunnel terminator for DIP-SIP key. */
extern int bcm_tunnel_terminator_add(
    int unit, 
    bcm_tunnel_terminator_t *info);

/* Delete a tunnel terminator for DIP-SIP key. */
extern int bcm_tunnel_terminator_delete(
    int unit, 
    bcm_tunnel_terminator_t *info);

/* Update a tunnel terminator for DIP-SIP key. */
extern int bcm_tunnel_terminator_update(
    int unit, 
    bcm_tunnel_terminator_t *info);

/* Get a tunnel terminator for DIP-SIP key. */
extern int bcm_tunnel_terminator_get(
    int unit, 
    bcm_tunnel_terminator_t *info);

/* Set the valid payload VLANs for this WLAN tunnel. */
extern int bcm_tunnel_terminator_vlan_set(
    int unit, 
    bcm_gport_t tunnel, 
    bcm_vlan_vector_t vlan_vec);

/* Get the valid payload VLANs for this WLAN tunnel. */
extern int bcm_tunnel_terminator_vlan_get(
    int unit, 
    bcm_gport_t tunnel, 
    bcm_vlan_vector_t *vlan_vec);

/* Create a tunnel DSCP map instance. */
extern int bcm_tunnel_dscp_map_create(
    int unit, 
    uint32 flags, 
    int *dscp_map_id);

/* Destroy a tunnel DSCP map instance. */
extern int bcm_tunnel_dscp_map_destroy(
    int unit, 
    int dscp_map_id);

/* 
 * Get the { internal priority, color }-to-DSCP mapping in the specified
 * DSCP map.
 */
extern int bcm_tunnel_dscp_map_get(
    int unit, 
    int dscp_map_id, 
    bcm_tunnel_dscp_map_t *dscp_map);

/* 
 * Set the { internal priority, color }-to-DSCP mapping in the specified
 * DSCP map.
 */
extern int bcm_tunnel_dscp_map_set(
    int unit, 
    int dscp_map_id, 
    bcm_tunnel_dscp_map_t *dscp_map);

/* Set port egress { internal priority, color }-to-DSCP mapping. */
extern int bcm_tunnel_dscp_map_port_set(
    int unit, 
    bcm_port_t port, 
    bcm_tunnel_dscp_map_t *dscp_map);

/* Get port egress { internal priority, color }-to-DSCP mapping. */
extern int bcm_tunnel_dscp_map_port_get(
    int unit, 
    bcm_port_t port, 
    bcm_tunnel_dscp_map_t *dscp_map);

/* Set or get the global chip tunneling configuration. */
extern int bcm_tunnel_config_get(
    int unit, 
    bcm_tunnel_config_t *tconfig);

/* Set or get the global chip tunneling configuration. */
extern int bcm_tunnel_config_set(
    int unit, 
    bcm_tunnel_config_t *tconfig);

#endif /* BCM_HIDE_DISPATCHABLE */

/* Initialize a bcm_tunnel_initiator_t/bcmx_tunnel_initiator_t structure. */
extern void bcm_tunnel_initiator_t_init(
    bcm_tunnel_initiator_t *tunnel_init);

/* 
 * Initialize a bcm_tunnel_terminator_t/bcmx_tunnel_terminator_t
 * structure.
 */
extern void bcm_tunnel_terminator_t_init(
    bcm_tunnel_terminator_t *tunnel_term);

/* Initialize a bcm_tunnel_config_t/bcmx_tunnel_config_t structure. */
extern void bcm_tunnel_config_t_init(
    bcm_tunnel_config_t *tconfig);

/* Initialize a L3 tunnel bcm_tunnel_dscp_map_t structure. */
extern void bcm_tunnel_dscp_map_t_init(
    bcm_tunnel_dscp_map_t *dscp_info);

#endif /* defined(INCLUDE_L3) */

#endif /* __BCM_TUNNEL_H__ */
